package com.mall.business.controller;

import com.mall.business.domain.TProduct;
import com.mall.business.service.ITProductService;
import com.mall.business.service.ITProductUserMoneyService;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.pay.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 *
 * 商品信息
 *
 */
@RestController
@RequestMapping("/webApiProduct")
public class ApiProductController  extends BaseController {

    @Autowired
    private ITProductService productService;



    /**
     *
     * 商品列表(首页)
     *
     */
    @RequestMapping("/nologin/getIndexProductList")
    public TableDataInfo getIndexProductList(TProduct  vo){
        startPage();
        // 是否上架
        vo.setIsSj("1");
        vo.setSpLx("1");
        // 当前用户Id
        String currUserId = vo.getCurrUserId();
        List<TProduct> tProducts = productService.selectTProductListApp(vo);
        if(!StringUtils.isBlank(currUserId)){
            for (int i = 0; i < tProducts.size(); i++) {
                TProduct tProduct = tProducts.get(i);
                // 获取一客一价
                BigDecimal vipPrice = productService.getVipPrice(currUserId, tProduct.getId());
                tProducts.get(i).setVipPrice(vipPrice);
            }
        }
        return getDataTable(tProducts);
    }

    /**
     *
     * 商品详情
     *
     */
    @GetMapping(value = "/nologin/productDtail")
    public AjaxResult productDtail(TProduct  vo) {
        String currUserId = vo.getCurrUserId();
        TProduct tProduct = productService.selectTProductByIdApp(vo.getId(),currUserId);
        return AjaxResult.success(tProduct);

    }



    /**
     *
     * 积分商品列表分页
     *
     */
    @RequestMapping("/nologin/getJfProductList")
    public TableDataInfo getJfProductList(TProduct  vo){
        startPage();
        // 是否上架
        vo.setIsSj("1");
        vo.setSpLx("2");
        // 当前用户Id
        List<TProduct> tProducts = productService.selectTProductListApp(vo);
        return getDataTable(tProducts);
    }







}
